<?php
include_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

class RegisterForm2 extends Zend_Form
{
	/**
	 * Register_Form_2
	 *
	 * @var Register_Form_2
	 */
	protected static $_instance;	
	
	/**
	 * Zend_View
	 *
	 * @var Zend_View
	 */
	static protected $_tmpView;	
	
	public function getInstance()
	{
		if(null == self::$_instance){	
			self::$_instance = new self();
		}
		
		return self::$_instance;
	}
	
	/**
	 * 
	 * Form for Register Step 2
	 *
	 */
	public function __construct($options = null)
	{
		
		if(null == self::$_tmpView)
		{
			self::$_tmpView = new Zend_View();
		}
		
		$this->setAttribs(array(
			'id' 	=> 'register-form2',
			'name' 	=> 'register-form2',
			'action'=> $installDir['value'].'userpanel.php?ad=wd',
			'method'=> 'POST'
		));
		
		$oldPassword = new Zend_Form_Element_Password('accOldPassword');
		$oldPassword->setLabel('Old Password: ')
				 ->setAttrib('id','acc-password')
				 ->setRequired(TRUE)
				 ->addValidator('NotEmpty',TRUE);
				 
		$password = new Zend_Form_Element_Password('accPassword');
		$password->setLabel('New Password: ')
				 ->setAttrib('id','acc-password')
				 ->setRequired(TRUE)
				 ->addValidator('NotEmpty',TRUE);

		$password_check = new Zend_Form_Element_Password('accPassword_check');
		$password_check->setLabel('Re-enter password: ')
				 	   ->setAttrib('id','acc-password_check')
				 	   ->setRequired(TRUE)
				 	   ->addValidator('NotEmpty',TRUE);
				 
				 
		$submit = new Zend_Form_Element_Submit('button');		
		$submit->setLabel('Update');					
        $this->addElements(array($oldPassword, $password, $password_check, $submit));
        
		$this->addDecorator('FormElements')
			 ->addDecorator('HtmlTag', array('tag' => 'table'))
			 ->addDecorator('Form');
		$this->setElementDecorators(array(
		    'ViewHelper',
		    'Errors',
		    'Description',
		    array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
		    array('Label', array('tag' => 'td')),
		    array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
		));
	}
	
	public function render()
	{
		return parent::render(self::$_tmpView);
	}	
	
	public function isValid($data)
	{
		$check2 = ($data['accPassword'] == $data['accPassword_check']);
		if (!$check2)
		{
			$this->getElement('accPassword_check')->setDescription('New password did not match');
		}
		return (parent::isValid($data) && $check2);
	}
}

?>